// 纯净基础插件

string author = "Live";
string pluginName = "Base 基础插件";
string version = "1.0";

// 插件初始化
void OnPluginInit()
{
    // 设置插件信息
    PluginData::SetAuthor(author);
    PluginData::SetName(pluginName);
    PluginData::SetVersion(version);

    // 加载后提示信息
    ThePresident.InfoFeed("插件:"+pluginName+"| 版本:"+version+"| 作者:"+author,false);
	
	// 当玩家说
    Events::Player::PlayerSay.Hook( @PlayerSay );
	// 当玩家连接后
    Events::Player::OnPlayerConnected.Hook( @OnPlayerConnected );
	// 当玩家被杀死后
    Events::Player::OnPlayerKilledPost.Hook( @OnPlayerKilledPost );
	
	ThePresident_OnMapStart();
	
}

// 地图开始
void ThePresident_OnMapStart(){
	// 服务器中文名
    Engine.RunConsoleCommand( "hostname [CN.Live] 纯净 | 猎杀专属服 ch QQ群392635015");
	ThePresident_OnRoundStart();
}

// 回合开始
void ThePresident_OnRoundStart()
{
	// 仅AI丧尸（玩家死亡不会变丧尸）
    //Engine.RunConsoleCommand( "cg_zombie_ai_only 1" );
    // 无感染
    //Engine.RunConsoleCommand( "cg_infection_disabled 1" );
}

// 当玩家连接后
HookReturnCode OnPlayerConnected(CTerrorPlayer@ pPlayer)
{

	Chat.PrintToChat(pPlayer,"欢迎进入本服务器,本服为纯净猎杀,有任何游戏和插件问题，欢迎进群交流：392635015");
	return HOOK_CONTINUE;

}

//当玩家死亡后
HookReturnCode OnPlayerKilledPost(CTerrorPlayer@ pPlayer)
{
	Chat.PrintToConsole(all,"玩家"+pPlayer.GetPlayerName()+"死亡，他的索引："+pPlayer.entindex());
	return HOOK_CONTINUE;
}

// 当玩家say
HookReturnCode PlayerSay(CTerrorPlayer@ pPlayer, CASCommand@ pArgs)
{
	string arg = pArgs.Arg( 1 );
	string arg1 = "";
	string arg2 = "";

	// 切分字符串(这样就可以用空格传一个命令参数了)
	int subIndex = arg.findFirst(" ",0);
	if(not (subIndex < 0)){
		arg1 = arg.substr(0,subIndex);
		arg2 = arg.substr(subIndex+1,-1);
		//Chat.PrintToChat(all,""+arg1+"|"+arg2);
	}else{
		arg1 = arg;
	}
	
	if( AdminSystem.AdminExist(pPlayer) ){
		if( arg1 == "!give" ){
			if( arg2 != "" ){
				pPlayer.GiveWeapon(arg2);
			}
		}else if( arg1 == "!fh" ){
			if( arg2 != "" ){
				if( arg2 == "all" ){
					array<int> playerList = Utils.CollectPlayers();
					for(uint i=0;i<playerList.length();i++){
						CTerrorPlayer@ player = ToTerrorPlayer(playerList[i]);
						if(not (player.GetTeamNumber() == TEAM_SURVIVOR)){
							player.ChangeTeam( TEAM_SURVIVOR );
							player.Respawn();
							Vector teleV = pPlayer.GetAbsOrigin();
							player.SetAbsOrigin(teleV);
						}
					}
					Chat.PrintToChat(all,"管理员复活了所有玩家");
				}else{
					CTerrorPlayer@ splayer = ToTerrorPlayer( parseInt(arg2,10,0) );
					if(splayer is null) return HOOK_CONTINUE;
					// 修改被复活玩家的游戏阵营
					splayer.ChangeTeam( TEAM_SURVIVOR );
					// 复活玩家
					splayer.Respawn();
					Chat.PrintToChat(all,"{hotpink}管理员使用命令复活了["+splayer.GetPlayerName()+"]");
				}
			}else{
				// 修改被复活玩家的游戏阵营
				pPlayer.ChangeTeam( TEAM_SURVIVOR );
				// 复活玩家
				pPlayer.Respawn();
			}
		}
	}
	return HOOK_CONTINUE;
}
